/**
 * Created by root on 16-12-29.
 */

jQuery(function () {
    table_num();
})

function change_nav(this_id) {
    var id = $(this_id).val();

    $.get({
        'url':'/nav/configMenu/',
        'data':{nav_id:id},
        'success':function (callback) {
            $('tbody').empty();
            var table_data = JSON.parse(callback);
            var num = 1;
            table_data.forEach(function (data) {
                $('tbody').append('<tr style="text-align: center;height: 25px">'+
                                        '<td style="display: none" id="td_id">'+data["id"]+'</td>'+
                                        '<td style="display: none;" id="td_nav_id">'+data["nav_id"]+'</td>'+
                                        '<td id="td_num">'+num+'</td>'+
                                        '<td id="td_navName">'+data["nav_name"]+'</td>'+
                                        '<td id="td_name">'+data["name"]+'</td>'+
                                        '<td id="td_order">'+data["order"]+'</td>'+
                                        '<td id="td_describe">'+data["describe"]+'</td>'+
                                        '<td>'+
                                            '<a style="height: 20px;font-size: 8px;padding-top: 2px;padding-bottom: 1px" class="btn btn-info" onclick="del(this)">删除</a>&nbsp;&nbsp;'+
                                            '<a style="height: 20px;font-size: 8px;padding-top: 2px;padding-bottom: 1px" class="btn btn-info" onclick="modify(this)">修改</a>'+
                                        '</td>'+
                                    '</tr>')
            })
            num += 1;
        }
    })
}

function modify(this_id) {
    var id = $(this_id).parent().parent().children('#td_id').text();
    var nav_id = $(this_id).parent().parent().children('#td_nav_id').text();
    var name = $(this_id).parent().parent().children('#td_name').text();
    var order = $(this_id).parent().parent().children('#td_order').text();
    var describe = $(this_id).parent().parent().children('#td_describe').text();
    console.log(id)

    $("[name='id']").val(id);
    $("[name='name']").val(name);
    $("[name='order']").val(order);
    $("[name='describe']").val(describe);
    $("[name='name']").val(name);
    $("[name='nav_id']").val(nav_id);
    console.log($("[name='id']").val())

    $('#form').attr('action','/nav/configMenu/modify');
    $('#add').text('修改');
}

function del(this_id) {
    var id = $(this_id).parent().parent().children("#td_id").text();
    var url = '/nav/configMenu/delete';
    $.post({
        url:url,
        data:{id:id}});
    window.location.reload();
}